import re

class ial:
	def __init__(self, parent):
		self.ial = []
		self.irc = parent
		self.remask = self.irc.rfc2812_mask()

	def isMask(self, mask):
		value = self.remask.match(mask)
		if value != None:
			return True
		return False

	def add(self, mask): 
		if validateMask(mask):
			self.ial.append(mask)
			return self.ial[len(self.ial)-1]

	def remove(self, mask, search=""):
		if search == "":
			self.ial.remove[mask]
			return True
		else:
			new = self.search(mask)
			if new != "":
				self.ial.remove[new]
				return True
			return False

	def search(self, search): # allows wildcards (*) 
		list = []
		regex = re.compile(search.replace("*", "[a-zA-Z0-9\x5B-\x60\x7B-\x7D\2E\5F\2D]+"))
		for i in self.ial:
			if regex.search(i) != None:
				list.append(i)

		return list 

	def getNick(self, mask):
		return mask.split("!")[0]

	def getUser(self, mask):
		return mask.split("!")[1].split("@")[0]

	def getHost(self, mask):
		return mask.split("@")[1]
